package com.yjt.fresh.widget;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.yjt.fresh.MyApp;
import com.yjt.fresh.R;
import com.yjt.fresh.utils.CommonsToolsHelper;

/**
 * 自定义Toast
 * Created by mcc on 2018-07-17.
 */

public class CustomToastResult {
    /**
     * 展示toast==LENGTH_SHORT
     *
     * @param msg
     */
    public static void show(String msg) {
        show(msg, Toast.LENGTH_SHORT);
    }
    /**
     * 展示toast==LENGTH_LONG
     *
     * @param msg
     */
    public static void showLong(String msg) {
        show(msg, Toast.LENGTH_LONG);
    }


    private static void show(String massage, int show_length) {
        Context context = MyApp.getContext();
        //使用布局加载器，将编写的toast_layout布局加载进来
        View view = View.inflate(context, R.layout.app_toast_result, null);
        TextView tv = view.findViewById(R.id.tvAppToastResult);
        ImageView iv = view.findViewById(R.id.ivAppToastResult);

        tv.setText(massage);
        Toast toast = new Toast(context);
        //设置Toast要显示的位置，水平居中并在底部，X轴偏移0个单位，Y轴偏移70个单位，
        toast.setGravity(Gravity.CENTER, 0, 0);
        //设置显示时间
        toast.setDuration(show_length);

        toast.setView(view);
        toast.show();
    }

    public static void showWithIvID(String massage, int show_length,int ivID) {
        Context context = MyApp.getContext();
        //使用布局加载器，将编写的toast_layout布局加载进来
        View view = View.inflate(context, R.layout.app_toast_result, null);
        TextView tv = view.findViewById(R.id.tvAppToastResult);
        ImageView iv = view.findViewById(R.id.ivAppToastResult);
        iv.setImageResource(ivID);
        tv.setText(massage);
        Toast toast = new Toast(context);
        //设置Toast要显示的位置，水平居中并在底部，X轴偏移0个单位，Y轴偏移70个单位，
        toast.setGravity(Gravity.CENTER, 0, 0);
        //设置显示时间
        toast.setDuration(show_length);

        toast.setView(view);
        toast.show();
    }

}
